package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysConfig;
import io.mybatis.example.springboot.service.SysConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_config - 参数配置表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysConfigs")
public class SysConfigController {

  @Autowired
  private SysConfigService sysConfigService;

  @PostMapping
  public DataResponse<SysConfigDO> save(@RequestBody SysConfigDO sysConfig) {
    return DataResponse.ok(sysConfigService.save( sysConfig));
  }

  @GetMapping
  public RowsResponse<SysConfigDO> findList(@RequestBody SysConfigDO sysConfig) {
    return RowsResponse.ok(sysConfigService.findList( sysConfig));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysConfigDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysConfigService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysConfigDO> update(@PathVariable("id") Long id, @RequestBody SysConfigDO sysConfig) {
    sysConfig.setId(id);
    return DataResponse.ok(sysConfigService.update( sysConfig));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysConfigService.deleteById(id) == 1);
  }

}
